package com.leetcode.题库;

import com.leetcode.common.model.ListNode;

/**
 * @author 覃国强
 * @date 2022-03-23 19:38
 */
public class 题库_0203_移除链表元素 {


  static
  class Solution {
    public ListNode removeElements(ListNode head, int val) {
      while (head != null && head.val == val) {
        head = head.next;
      }
      if (head == null) {
        return head;
      }

      ListNode node = head;
      while (node.next != null) {
        if (node.next.val == val) {
          node.next = node.next.next;
        } else {
          node = node.next;
        }
      }

      return head;
    }
  }

}
